package com.qibo.cashier;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.LinearLayout;

import com.qibo.arouterlib.ARouterCenter;
import com.qibo.baselib.adapter.CommonAdapter;
import com.qibo.baselib.adapter.ViewHolder;
import com.qibo.baselib.base.BaseActivity;
import com.qibo.baselib.utils.UpDateAppUtil;

import java.util.ArrayList;

public class MainActivity  extends BaseActivity{
    LinearLayout mian_ll_receipt;
    GridView mGridView;
    private ArrayList<GridCutItem> mDatas = new ArrayList<>();
    //private UpdateInfo updateInfo;
    @Override
    protected int getContentViewId() {
        return R.layout.activity_main;
    }

    @Override
    protected void initView() {
        mian_ll_receipt = findViewById(R.id.mian_ll_receipt);
        mGridView = findViewById(R.id.mGridView);
    }

    @Override
    protected void initAction() {
        mian_ll_receipt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                onMenuClick(4);
            }
        });
        getUpdateApp();
    }

    @Override
    protected void initData() {
        mDatas.clear();
        for(int i = 0; i< GridCutItem.gridDatasicon.length; i++) {
            GridCutItem gridCutItem = new GridCutItem();
            gridCutItem.setName(GridCutItem.gridDatastxt[i]);
            gridCutItem.setIcon(GridCutItem.gridDatasicon[i]);
            mDatas.add(gridCutItem);
        }
        mGridView.setAdapter(new CommonAdapter<GridCutItem>(mContext, mDatas, R.layout.layout_gridview_item) {
            @Override
            public void convert(ViewHolder helper, final GridCutItem item, int position) {
                helper.setText(R.id.layout_gridview_item_tv, item.getName());
                helper.setImageResource(R.id.layout_gridview_item_iv, item.getIcon());
            }
        });
        mGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                onMenuClick(position);
            }
        });
    }

    public void onMenuClick(int position) {
    switch (position){
        //收款
        case 0:
            ARouterCenter.toRecharMainActivity();
            break;
        //充值
        case 1:
            ARouterCenter.toCardMainActivity();
            break;
        //办卡
        case 2:
            ARouterCenter.toOrderMainActivity();
            break;
        //订单
        case 3:
            ARouterCenter.toSettingMainActivity();
            break;
        //收款
        case 4:
            ARouterCenter.toReceiptMainActivity();
            break;
       }
    }

    public void getUpdateApp(){
        UpDateAppUtil.getUpdateInfo(MainActivity.this,"http://paywhere.kongzue.com/downloads/paywhere.apk","V3.6.5");

    }

}
